//
//  RNTimeUtils.m
//  ModifyMetroDemo
//
//  Created by Marcus on 2020/3/8.
//  Copyright © 2020 Facebook. All rights reserved.
//

#import "RNTimeUtils.h"

static RNTimeUtils *instance;

@implementation RNTimeUtils

+ (RNTimeUtils *) instance{
  @synchronized(self) {
    if (!instance) {
      instance = [[self alloc] init];
    }
  }
  return instance;
}

- (void)startTimeRecord{
  self.startTime = [self getCurrentTimestamp];
};

- (void)endTimeRecord{
  self.endTime = [self getCurrentTimestamp];
};

- (void)printTimeCost{
  NSLog(@"--------------------------");
  NSLog(@"| Time Cost: %ld", (self.endTime - self.startTime));
  NSLog(@"--------------------------");
};

- (long)getTimeCost{
  return self.endTime -self.startTime;
}

- (NSTimeInterval)getCurrentTimestamp {
  NSDate *date = [NSDate dateWithTimeIntervalSinceNow:0]; // 获取当前时间0秒后的时间
  NSTimeInterval time = [date timeIntervalSince1970]*1000;// *1000 是精确到毫秒(13位),不乘就是精确到秒(10位)
  return time;
}

@end
